package cvc.framework.controller;

import cvc.framework.entity.WebSocketMessage;
import cvc.framework.result.RestMessage;
import cvc.framework.result.RestResult;
import cvc.framework.service.GroupsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/Groups")
public class GroupsController {
    @Autowired
    GroupsService groupsService;


    //获取所有关联关系信息
    @RequestMapping("/getGroups")
    public RestResult getGroups(String targetName, String uuid) {
        RestResult res = new RestResult();
        res.message = new RestMessage();
        res.message.data = groupsService.getGroups(targetName, uuid);
        return res;
    }

    //通过id获取关联关系信息
    @RequestMapping("/getGroupById")
    public RestResult getGroupById(String targetName, String uuid, String id) {
        RestResult res = new RestResult();
        res.message = new RestMessage();
        res.message.data = groupsService.getGroupById(targetName, id, uuid);
        return res;
    }

    //添加关联关系信息
    @PostMapping(value = "/addGroup")
    public RestResult addGroup(@RequestBody WebSocketMessage message) {
        System.out.println(message.toString());
        RestResult res = new RestResult();
        res.message = new RestMessage();
        res.message.data = groupsService.addGroup(message);
        return res;
    }

    //修改关联关系信息
    @PostMapping(value = "/updateGroup")
    public RestResult updateGroup(@RequestBody WebSocketMessage message) {
        System.out.println(message.toString());
        RestResult res = new RestResult();
        res.message = new RestMessage();
        res.message.data = groupsService.updateGroup(message);
        return res;
    }

    //删除关联关系信息
    @RequestMapping("/deleteGroup")
    public RestResult deleteGroup(String targetName, String uuid, String id) {
        RestResult res = new RestResult();
        res.message = new RestMessage();
        res.message.data = groupsService.deleteGroup(targetName, uuid, id);
        return res;
    }
}
